package kr.hkit.powerjava.chapter24.work;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

public class TestMain {
	public static void main(String[] args) {
		StudentDAO dao = new StudentDAO();
	/*	dao.insertItem(new Student(1, "김태희", 90, 80, 70));
		dao.insertItem(new Student(2, "박신혜", 100, 100, 100));
		dao.insertItem(new Student(3, "이민정", 90, 80, 70));
		dao.saveList();*/
		
		dao.prnItem();
		/*dao.insertItem(new Student(4, "효린", 70, 80, 70));
		dao.saveList();*/
		
	/*	ArrayList<Student> arList = new ArrayList<>();
		
		Student std = new Student(1, "김태희", 90, 80, 70);		
		Student std2 = new Student(2, "박신혜", 100, 100, 100);
		
		arList.add(std);
		arList.add(std2);
		
		ObjectOutputStream oos = null;
		ObjectInputStream ois = null;
		
		try {
			oos = new ObjectOutputStream(new FileOutputStream("StudentList.dat"));
			oos.writeObject(arList);
			oos.flush();
			
			ois = new ObjectInputStream(new FileInputStream("StudentList.dat"));
			ArrayList<Student> list;
			
			list = (ArrayList<Student>) ois.readObject();
		
			for(Student st : list){
				System.out.println(st);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e){
			e.printStackTrace();
		} finally {
			if (oos != null) try {oos.close();} catch (Exception e){} 
			if (ois != null) try {ois.close();} catch (Exception e){}
			}*/
		}
	}